package com.problem.leetcode;

import java.util.Arrays;

/**
 * 解法:最搓的算法 就是使用排序 时间复杂度o(nlog2)
 *
 * @author didi
 * @DESCRIPTION
 * @create 2019-04-28 18:51
 **/

public class Problem961 {
    public int repeatedNTimes(int[] A) {
        Arrays.sort(A);

        int left  = A[(A.length >> 1) - 1], tmp = left;
        int right = A[(A.length >> 1)];

        if (left != right && right != A[A.length - 1]) {
            tmp = left;
        } else {
            tmp = right;
        }

        return tmp;
        // for (int i = 0; i < A[A.length - 1]; i++) {
        //     if (A[i] == A[i + 1]) {
        //         return A[i];
        //     }
        // }
        //
        // return A[0];
    }
}
